<template>
  <FormView
    v-model="entity"
    :title="entity.id ? '修改楼栋管理' : '新建楼栋管理'"
    :toolbar-attrs="{ buttons: ['back', 'save', 'cancel'] }"
    :toolbar-listeners="{ save: persist }">
    <FormHolder ref="form" label-width="100px" :model="entity">
      <FormItemGroup block-title="基本信息">
        <FormSelect v-model="entity.status" prop="status" label="使用状况" dict-type="edifice_usage_status" required />
        <FormTreeSelect
          v-model="entity.regionalId"
          :span="12"
          label="所属区哉"
          :options="regionalTreeData"
          prop="regionalId"
          required />

        <FormInput v-model="entity.name" prop="name" label="楼栋名称" :span="24" max-length="255" required />
        <FormInput v-model="entity.code" prop="code" label="楼栋编码" disabled />
        <FormInput v-model="entity.assetNumber" prop="assetNumber" max-length="255" abel="资产编码" />
        <FormInput v-model="entity.location" prop="location" label="楼栋座落" max-length="255" required />
        <FormInput v-model="entity.acquireWay" prop="acquireWay" max-length="50" label="取得方式" />
        <FormInputNumber v-model="entity.usefulLife" prop="usefulLife" :min="0" :max="9999" label="使用年限" />
        <FormInput v-model="entity.practicalUse" prop="practicalUse" label="实际用途" max-length="50" />
        <FormInput v-model="entity.permittedUse" prop="permittedUse" label="批准用途" max-length="50" />
        <FormInput v-model="entity.ownershipNumber" prop="ownershipNumber" label="权属证号" max-length="50" />
        <FormInput v-model="entity.ownershipProve" prop="ownershipProve" label="权属证明" max-length="50" />
        <FormInput v-model="entity.ownershipType" prop="ownershipType" label="权属性质" max-length="50" />
        <FormDatePicker
          v-model="entity.builddate"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          label="取得日期"
          prop="builddate" />
        <FormDatePicker
          v-model="entity.issuingDate"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          label="发证时间"
          prop="issuingDate" />
        <FormInput v-model="entity.sourcesFunds" prop="sourcesFunds" label="资金来源" max-length="255" />
        <FormInput v-model="entity.measureUnit" prop="measureUnit" label="计量单位" max-length="32" />
        <FormDatePicker
          v-model="entity.completionDate"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          label="竣工日期"
          prop="completionDate" />
        <FormSelect
          v-model="entity.buildingStructure"
          prop="buildingStructure"
          label="建筑结构"
          dict-type="edifice_building_structure" />
        <FormSelect
          v-model="entity.seismicGrade"
          prop="seismicGrade"
          label="抗震级别"
          dict-type="edifice_earthquake_resistance_level" />
        <FormInputNumber v-model="entity.upFloor" prop="upFloor" label="地上层数" :min="0" :max="9999" />
        <FormInputNumber v-model="entity.downFloor" prop="downFloor" label="地下层数" :min="0" :max="9999" />
        <FormInputNumber v-model="entity.upArea" prop="upArea" label="地上面积" :min="0" :max="999999999" />
        <FormInputNumber v-model="entity.downArea" prop="downArea" label="地下面积" :min="0" :max="999999999" />
        <FormInputNumber v-model="entity.floorcount" prop="floorcount" label="总层数" :min="0" :max="999999999" />
        <FormInputNumber v-model="entity.coveredArea" prop="coveredArea" label="占地面积" :min="0" :max="999999999" />
        <FormInputNumber v-model="entity.floorage" prop="floorage" label="建筑面积" :min="0" :max="999999999" />
        <FormSelect
          v-model="entity.sourceAssets"
          prop="sourceAssets"
          label="资产来源"
          dict-type="edifice_scurce_assets" />
        <FormDatePicker
          v-model="entity.useDate"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          label="使用日期"
          prop="useDate" />
        <FormInput v-model="entity.x" prop="x" label="经度" max-length="15" />
        <FormInput v-model="entity.y" prop="y" label="纬度" max-length="15" />
        <FormTextarea v-model="entity.remarks" rows="5" prop="remarks" label="备注" max-length="3000" />
      </FormItemGroup>
      <FormItemGroup :gutter="0" block-title="附件信息">
        <UploadPage
          v-if="entity.unid"
          ref="UploadPage"
          style="padding: 0"
          :unique-code="entity.unid"
          model="space"
          classify="regional" />
      </FormItemGroup>
    </FormHolder>
  </FormView>
</template>

<script>
  import { addObj, putObj, getObj, createObj } from '@/api/space/fyroomedifice'
  import { regionalFetchTree } from '@/api/space/fyroomregional'
  import form from '@/vue/mixin/form'

  export default {
    name: 'EdificeForm',
    relativeViewId: 'EdificeView',

    mixins: [form],
    data() {
      return {
        entity: {
          id: '',
          tenantId: null,
          deptId: null,
          deptFullname: null,
          createBy: null,
          createId: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          delFlag: null,
          unid: '9009514a-0f70-4d90-89dd-9b0ff806c64c',
          status: null,
          regionalId: null,
          regionalMc: null,
          regionalFullcode: null,
          name: null,
          code: null,
          assetNumber: null,
          location: null,
          acquireWay: null,
          usefulLife: null,
          practicalUse: null,
          permittedUse: null,
          ownershipNumber: null,
          ownershipProve: null,
          ownershipType: null,
          builddate: null,
          issuingDate: null,
          sourcesFunds: null,
          measureUnit: null,
          completionDate: null,
          buildingStructure: null,
          seismicGrade: null,
          upFloor: null,
          downFloor: null,
          upArea: null,
          downArea: null,
          floorcount: null,
          coveredArea: null,
          floorage: null,
          sourceAssets: null,
          useDate: null,
          dataCode: null,
          ordernumber: null,
          x: null,
          y: null,
          remarks: null,
          dictOption: {
            buildingStructureList: [],
            usageStatusList: [],
            earthquakeResistanceLevelList: [],
            edificeScurceAssetsList: []
          }
        },
        regionalTreeData: []
      }
    },
    created() {
      this.init()
    },
    methods: {
      create: createObj,
      load: getObj,
      save: addObj,
      update: putObj,
      async init() {
        const res = await regionalFetchTree()
        this.regionalTreeData = res.data.data
      }
    }
  }
</script>
